package com.nbjtjc.safe.api.danger;

import com.nbjtjc.common.validator.ValidatorUtils;
import com.nbjtjc.common.validator.group.UpdateGroup;
import com.nbjtjc.safe.annotation.SysLog;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.danger.DangerInspectPublicMapper;
import com.nbjtjc.safe.mapper.sys.SysFileMapper;
import com.nbjtjc.safe.mapper.sys.SysUserMapper;
import com.nbjtjc.safe.model.danger.DangerInspectPublic;
import com.nbjtjc.safe.service.danger.DangerInspectPublicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @auther guqianbin
 * @date 2018/4/12 13:20
 * 隐患检查发布
 **/
@RestController
@RequestMapping("/danger/inspectPublic")
@CrossOrigin("*")
public class DangerInspectPublicController {

    @Autowired
    private DangerInspectPublicService dangerInspectPublicService;

    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired
    private DangerInspectPublicMapper dangerInspectPublicMapper;

    @Autowired
    private SysFileMapper sysFileMapper;

    @SysLog("添加发布检查表")
    @RequestMapping(value = "/add", method = {RequestMethod.POST})
    public Result add(@RequestBody DangerInspectPublic dangerInspectPublic) {
        ValidatorUtils.validateEntity(dangerInspectPublic);
        Result result = dangerInspectPublicService.add(dangerInspectPublic);
        return result;
    }

    @SysLog("删除发布的检查表")
    @RequestMapping(value = "/delete", method = {RequestMethod.POST})
    public Result delete(@RequestBody DangerInspectPublic dangerInspectPublic) {
        ValidatorUtils.validateEntity(dangerInspectPublic, UpdateGroup.class);
        Result result = dangerInspectPublicService.delete(dangerInspectPublic);
        return result;
    }

    @SysLog("更新发布的检查表")
    @RequestMapping(value = "/update", method = {RequestMethod.POST})
    public Result update(@RequestBody DangerInspectPublic dangerInspectPublic) {
        ValidatorUtils.validateEntity(dangerInspectPublic, UpdateGroup.class);
        Result result = dangerInspectPublicService.update(dangerInspectPublic);
        return result;
    }

    @SysLog("查找发布的检查表")
    @RequestMapping(value = "/find", method = {RequestMethod.POST})
    public Result find(@RequestBody DangerInspectPublic dangerInspectPublic) {
        Result result = dangerInspectPublicService.find(dangerInspectPublic);
        return result;
    }

    @SysLog("查找发布的检查表,仅检查表")
    @RequestMapping(value = "/findSimple", method = {RequestMethod.POST})
    public Result findSimple(@RequestBody DangerInspectPublic dangerInspectPublic){
        Result result = dangerInspectPublicService.findSimple(dangerInspectPublic);
        return result;
    }

    @PostMapping("/search")
    public Result search(@RequestBody DangerInspectPublic dangerInspectPublic) {
        Result result = dangerInspectPublicService.search(dangerInspectPublic);
        return result;
    }

    @GetMapping("/summary/{year}")
    public Result summary(@PathVariable("year") int year){
        Result result = new Result();
        result.setData(dangerInspectPublicService.summary(year));
        return result;
    }

    @RequestMapping(value = "/detail", method = {RequestMethod.POST})
    public Result detail(@RequestBody DangerInspectPublic dangerInspectPublic) {
        ValidatorUtils.validateEntity(dangerInspectPublic, UpdateGroup.class);
        Result result = new Result();
        result = dangerInspectPublicService.detail(dangerInspectPublic);
        return result;
    }
    @RequestMapping(value = "/detailNew", method = {RequestMethod.POST})
    public Result detailNew(@RequestBody DangerInspectPublic dangerInspectPublic) {
        ValidatorUtils.validateEntity(dangerInspectPublic, UpdateGroup.class);
        Result result = new Result();
        result = dangerInspectPublicService.detailNew(dangerInspectPublic);
        return result;
    }

    @RequestMapping(value = "/saveTaskTable", method = {RequestMethod.POST})
    public Result saveTaskTable(@RequestBody DangerInspectPublic dangerInspectPublic){
        Result result=new Result();
        result=dangerInspectPublicService.saveTaskTable(dangerInspectPublic);
        return result;
    }
}
